package com.mysnail.method;

import freemarker.template.SimpleSequence;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortMathod implements TemplateMethodModelEx{
    @Override
    public Object exec(List list) throws TemplateModelException {
        //获取第一个参数
        SimpleSequence arg0 = (SimpleSequence) list.get(0);
        List<BigDecimal> list1 = arg0.toList();

        Collections.sort(list1, new Comparator<BigDecimal>() {

            @Override
            public int compare(BigDecimal o1, BigDecimal o2) {
                return o1.intValue()-o2.intValue();//升序 o2.intValue()-o1.intValue()表示降序
            }
        });
        return list1;
    }
}
